package thinkingInJava.String_.regex_;

//strings/RegEx11.java
//TIJ4 Chapter Strings, Exercise 11, page 533 
/* Apply the regular expression
*	(?i)((^[aeiou])|(\\s+[aeiou]))\\w+[aeiou]\\b
* 	to
*	Arline ate eight apples and one orange while Anita hadn't any
*/
//(alternate solution) Note double \\ required for \\s+, \\w+ and \\b in compile(): 

import java.util.regex.*;

public class RegEx11 {
	public static void main(String[] args) {
		Pattern p = 
	Pattern.compile("(?i)((^[aeiou])|(\\s+[aeiou]))\\w+[aeiou]\\b");
		Matcher m = p.matcher("Arline ate eight apples and one orange while Anita hadn't any");
		while(m.find())
			System.out.println("Match \"" + m.group() + "\" at " + m.start());
	}
}
// http://bbs.csdn.net/topics/300069256
//(^[aeiou])|(\s+[aeiou])
//==========================================
//^[aeiou] 匹配字符串开头是aeiou的其中一个字母
//\s+[aeiou] 匹配一个或多个空格后面跟着aeiou的其中一个字母
//| [或者]操作符
//(^[aeiou])|(\s+[aeiou]) 匹配两种情况的一种
// (?i)在Java下意思为：“启用不区分大小写的匹配”
// 说白了，就是以元音字母开头或者以空白符加元音字母开头的串都满足～～
// ^表示的是字符串的开头，所以^[aeiou]不应该理解为非元音字母（[^aeiou]才是指非元音字母！），正如二楼所言，^[aeiou]的匹配项为字符串开头是元音的字母。
